<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0px;
            padding: 0px;
        }

        body {
            height: 100vh;
            width: 100vw;
        }

        canvas {
            display: block;
        }
    </style>
</head>

<body>
    <canvas id="can"></canvas>
    <script>
        var canvas = document.getElementById('can')
        var ctx = canvas.getContext('2d')
        canvas.width = window.innerWidth;
        canvas.height = window.innerHeight;
        canvas.style.backgroundColor = 'black'
        function RandomColor() {
            this.red = parseInt(Math.random() * 255)
            this.green = parseInt(Math.random() * 255)
            this.blue = parseInt(Math.random() * 255)
            return `rgb(${this.red},${this.green},${this.blue})`
        }
        function Word(i) {
            this.arr = []
            this.height = canvas.height
            this.width = canvas.width
            this.size = 20;
            this.xx = 15;
            this.x = i * this.xx ;
            this.y = 0;
            this.speed = this.size;
            this.fontColor = RandomColor();
            this.word = '东风夜放花千树'
            this.nowWord = this.word[parseInt(Math.random() * this.word.length)]
            this.init = function () {
                for (var i = 0; i < this.width / this.xx; i++) {
                    this.arr.push(new Word(i))
                }
            }
            this.draw = function () {
                ctx.beginPath()
                ctx.fillStyle = this.fontColor
                ctx.font = `${this.size}px Microsoft YaHei`
                ctx.fillText(this.nowWord, this.x, this.y)
                ctx.fill()
                ctx.closePath()
            }
            this.move = function () {
                this.y += this.speed;
                if (this.y >= this.height) {
                    this.y = 0
                    this.speed = Math.random() * 10 + this.size
                }
            }
            this.fill = function () {
                setInterval(() => {
                    ctx.fillStyle = 'rgba(0,0,0,0.1)'
                    ctx.fillRect(0, 0, canvas.width, this.height)
                    for (var i = 0; i < this.arr.length; i++) {
                        var item = this.arr[i]
                        item.move()
                        item.draw()
                    }
                }, 60)
            }
        }
        var word = new Word()
        word.init()
        word.fill()
    </script>
</body>

</html>